//
//  CydhSubView.m
//  上海杨浦
//
//  Created by FrankChen on 13-5-23.
//  Copyright (c) 2013年 FrankChen. All rights reserved.
//

#import "CydhSubView.h"
#import "CydhThdView.h"

@implementation CydhSubView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        //
        [self setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bgImg_cell"]]];
        [self AddImageView];
        [self AddBackBtn];
        [self addBtns:[self AddScrollView]];
    }
    return self;
}

-(void) AddImageView{
    UIImageView *imageView=[[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)]autorelease];
    [imageView setBackgroundColor:[UIColor blueColor]];
    [self AddLabel:imageView];
    [self addSubview:imageView];
}

-(void) AddLabel:(UIImageView *)imageView{
    UILabel *label=[[[UILabel alloc]initWithFrame:CGRectMake(124, 1, 80, 28)]autorelease];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:18.0f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor blueColor]];
    [label setTextColor:[UIColor whiteColor]];
    [label setText:@"常用电话"];
    [imageView addSubview:label];
}

-(void) AddBackBtn{
    UIButton *btn_back = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn_back setImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal];
    btn_back.frame = CGRectMake(15, 1, 72, 29);
    [btn_back addTarget:self action:@selector(Btn_Back_Clicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn_back];
}

-(void)Btn_Back_Clicked{
    [self removeFromSuperview];
}

-(UIScrollView *)AddScrollView{
    UIScrollView *scrollView=[[[UIScrollView alloc]initWithFrame:CGRectMake(0, 50, 320, 411)]autorelease];
    [scrollView setContentSize:CGSizeMake(320, 650)];
    [self addSubview:scrollView];
    return scrollView;
}

-(void)addBtns:(UIScrollView *)ScrollView{
    [self addLabelToScrollView:ScrollView :0 :@"政府部门"];
    [self addBtnToScrollView:ScrollView :30 :@"btn_tele1.png" :1];
    [self addLabelToScrollView:ScrollView :115 :@"街道、镇"];
    [self addBtnToScrollView:ScrollView :145 :@"btn_tele2.png" :2];
    [self addLabelToScrollView:ScrollView :230 :@"事业单位"];
    [self addBtnToScrollView:ScrollView :260 :@"btn_tele3.png" :3];
    [self addLabelToScrollView:ScrollView :345 :@"其他"];
    [self addBtnToScrollView:ScrollView :375 :@"btn_tele4.png" :4];
}

-(void)addLabelToScrollView:(UIScrollView *)ScrollView :(int) y_zuobiao :(NSString *)text{
    UILabel *label=[[[UILabel alloc]initWithFrame:CGRectMake(25, y_zuobiao, 320, 30)]autorelease];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:16.5f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setTextColor:[UIColor darkGrayColor]];
    [label setText:text];
    [ScrollView addSubview:label];
}

-(void)addBtnToScrollView:(UIScrollView *)ScrollView :(int) y_zuobiao :(NSString *)img :(int)flag{
    CGRect frame=CGRectMake(25, y_zuobiao, 270, 69);
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
    btn.frame = frame;
    switch (flag) {
        case 1:
            [btn addTarget:self action:@selector(Button1Clicked) forControlEvents:UIControlEventTouchUpInside];
            break;
        case 2:
            [btn addTarget:self action:@selector(Button2Clicked) forControlEvents:UIControlEventTouchUpInside];
            break;
        case 3:
            [btn addTarget:self action:@selector(Button3Clicked) forControlEvents:UIControlEventTouchUpInside];
            break;
        case 4:
            [btn addTarget:self action:@selector(Button4Clicked) forControlEvents:UIControlEventTouchUpInside];
            break;
            
    }
    
    [ScrollView addSubview:btn];
}

-(void)Button1Clicked{
    CydhThdView *thdView=[[CydhThdView alloc]initWithFrame:CGRectMake(0, 0, 320, 500)];
    [thdView initData:1];
    [self addSubview:thdView];
}

-(void)Button2Clicked{
    CydhThdView *thdView=[[CydhThdView alloc]initWithFrame:CGRectMake(0, 0, 320, 500)];
    [thdView initData:2];
    [self addSubview:thdView];
}

-(void)Button3Clicked{
    CydhThdView *thdView=[[CydhThdView alloc]initWithFrame:CGRectMake(0, 0, 320, 500)];
    [thdView initData:3];
    [self addSubview:thdView];
}

-(void)Button4Clicked{
    CydhThdView *thdView=[[CydhThdView alloc]initWithFrame:CGRectMake(0, 0, 320, 500)];
    [thdView initData:4];
    [self addSubview:thdView];
}

@end
